//
//  AudioVisualCollectionViewCell.m
//  HomeIn
//
//  Created by mac on 15/11/7.
//  Copyright © 2015年 ZZP. All rights reserved.
//

#import "AudioVisualCollectionViewCell.h"
#import "AudioVisualModel.h"
#import <UIImageView+WebCache.h>
#import "UIImageView+PJ.h"
#import "StringWithHeight.h"
@implementation AudioVisualCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self creader];
    }
    return self;
}
-(void)creader
{
    self.backImageView = [[UIImageView alloc] initWithFrame:CGRectMake(20,self.frame.size.height / 6,self.frame.size.height / 6 * 4,self.frame.size.height / 6 * 4)];
    [self.backImageView MasksToBounds:YES CornerRadius:self.backImageView.frame.size.width / 2];
    [self.contentView addSubview:self.backImageView];
    
    UIImageView * backImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
    [backImage setImage:[UIImage imageNamed:@"iconfont-yuyinshiting.png"]];
    [backImage setCenter:self.backImageView.center];
    [self.contentView addSubview:backImage];
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.backImageView.frame.origin.x * 2 + self.backImageView.frame.size.width, self.backImageView.frame.origin.y, (WIDTH - 20) * 0.533, 0.267 *self. frame.size.height)];
    //        [self.titleLabel setBackgroundColor:[UIColor yellowColor]];
    [self.titleLabel setNumberOfLines:2];
    [self.titleLabel setFont:[UIFont boldSystemFontOfSize:0.1 *self.frame.size.height]];
    [self.contentView addSubview:self.titleLabel];
    
    self.nicknameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + 0.067 *self.frame.size.height, self.titleLabel.frame.size.width, 0.133 *self.frame.size.height)];
    [self.nicknameLabel setFont:[UIFont systemFontOfSize:0.0867 *self.frame.size.height]];
    [self.contentView addSubview:self.nicknameLabel];
    
    UILabel * playLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.nicknameLabel.frame.origin.x, self.nicknameLabel.frame.origin.y + self.nicknameLabel.frame.size.height + 0.067 *self.frame.size.height, 0.086 *self.frame.size.width, self.nicknameLabel.frame.size.height)];
    [playLabel setFont:[UIFont systemFontOfSize:0.0867 *self.frame.size.height]];
    //        [playLabel setBackgroundColor:[UIColor yellowColor]];
    [playLabel setText:@"播放:"];
    [self.contentView addSubview:playLabel];
    
    self.playCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(playLabel.frame.origin.x + playLabel.frame.size.width + 5, playLabel.frame.origin.y, 0.086 *self.frame.size.width, self.nicknameLabel.frame.size.height)];
    [self.playCountLabel setFont:[UIFont systemFontOfSize:0.0867 *self.frame.size.height]];
    [self.contentView addSubview:self.playCountLabel];
    
    UILabel * timeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.playCountLabel.frame.origin.x + self.playCountLabel.frame.size.width + 20, self.playCountLabel.frame.origin.y, playLabel.frame.size.width, playLabel.frame.size.height)];
    [timeLabel setFont:[UIFont systemFontOfSize:0.0867 *self.frame.size.height]];
    //        [timeLabel setBackgroundColor:[UIColor yellowColor]];
    [timeLabel setText:@"时长:"];
    [self.contentView addSubview:timeLabel];
    
    self.durationLabel = [[UILabel alloc] initWithFrame:CGRectMake(timeLabel.frame.origin.x + timeLabel.frame.size.width + 5, timeLabel.frame.origin.y, timeLabel.frame.size.width * 2, timeLabel.frame.size.height)];
    [self.durationLabel setFont:[UIFont systemFontOfSize:0.0867 *self.frame.size.height]];
    //        [self.durationLabel setBackgroundColor:[UIColor yellowColor]];
    [self.contentView addSubview:self.durationLabel];
}
- (void)setModel:(AudioVisualModel *)model
{
    _model = model;
    [self.backImageView sd_setImageWithURL:[NSURL URLWithString:_model.cover_path] placeholderImage:nil];
    [self.titleLabel setText:_model.title];
    [self.nicknameLabel setText:[NSString stringWithFormat:@"by %@", _model.nickname]];
    [self.playCountLabel setText:[NSString stringWithFormat:@"%@", _model.count_play]];
    int m = (int)_model.duration.floatValue / 60;
    int f = (int)_model.duration.floatValue % 60;
    [self.durationLabel setText:[NSString stringWithFormat:@"%d:%d",m ,f]];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
